home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_077 / samples / hedit.d < prev    next >
Text File  |  1992-05-06  |  16KB  |  829 lines

  1. #include:util.g
  2. #include:crt.g
  3.  
  4. char CSI = '\(0x9b)';
  5.  
  6. uint BUFFSIZE = 1024;
  7.  
  8. uint
  9.     FILECOL = 12,
  10.     ROCOL = 2,
  11.     POSCOL = 33,
  12.     POSLEN = 6,
  13.     NUMLEN = 11,
  14.     HEXCOL = 7,
  15.     ERRORCOL = POSCOL + NUMLEN + 1;
  16.  
  17. uint NLines, NCols;
  18.  
  19. file(BUFFSIZE) Fyle;
  20. channel input binary ChIn;
  21. channel output binary ChOut;
  22. channel output text CRTOut;
  23.  
  24. *char FileName;
  25.  
  26. ulong FilePos, WindowPos, EndPos;
  27.  
  28. uint CursorLine, CursorColHex, CursorColChar;
  29.  
  30. bool ReadOnly, Binary, HadError;
  31.  
  32. proc err(*char message)void:
  33.  
  34.     CRT_Move(NLines - 1, ERRORCOL);
  35.     CRT_EnterHighLight();
  36.     write(CRTOut; message);
  37.     CRT_ExitHighLight();
  38.     HadError := true;
  39. corp;
  40.  
  41. proc abort(*char message)void:
  42.  
  43.     writeln("HEdit I/O error: ", message, ' ',
  44.         ioerror(ChIn), ' ', ioerror(ChOut));
  45.     if not ReadOnly then
  46.     close(ChOut);
  47.     fi;
  48.     close(ChIn);
  49.     close(CRTOut);
  50.     CRT_Abort();
  51. corp;
  52.  
  53. proc endOfFile()void:
  54.  
  55.     err("End of file");
  56. corp;
  57.  
  58. proc startOfFile()void:
  59.  
  60.     err("Beginning of file");
  61. corp;
  62.  
  63. proc displayPos()void:
  64.  
  65.     CRT_Move(NLines - 1, POSCOL);
  66.     write(CRTOut; FilePos : x : -POSLEN);
  67. corp;
  68.  
  69. proc displayStatus()void:
  70.     uint i;
  71.  
  72.     HadError := false;
  73.     CRT_ClearLine(NLines - 1);
  74.     for i from 0 upto NCols - 2 do
  75.     write(CRTOut; '-');
  76.     od;
  77.     CRT_Move(NLines - 1, FILECOL);
  78.     write(CRTOut; FileName);
  79.     if ReadOnly then
  80.     CRT_Move(NLines - 1, ROCOL);
  81.     write(CRTOut; "[RO]");
  82.     fi;
  83.     displayPos();
  84.     CRT_Move(NLines - 1, HEXCOL);
  85.     write(CRTOut; if Binary then "hex-" else "char" fi);
  86. corp;
  87.  
  88. proc clearError()void:
  89.     uint i;
  90.  
  91.     if HadError then
  92.     HadError := false;
  93.     CRT_Move(NLines - 1, ERRORCOL);
  94.     for i from ERRORCOL + 2 upto NCols do
  95.         write(CRTOut; '-');
  96.     od;
  97.     fi;
  98. corp;
  99.  
  100. proc getChar()char:
  101.     char ch;
  102.  
  103.     ch := CRT_ReadChar();
  104.     clearError();
  105.     ch
  106. corp;
  107.  
  108. proc ASCIIPut(byte b)void:
  109.  
  110.     write(CRTOut; if b + '\e' >= ' ' and b + '\e' <= '~' then
  111.               b + '\e'
  112.           else
  113.               '.'
  114.           fi);
  115. corp;
  116.  
  117. proc seek(ulong pos)void:
  118.  
  119.     if not SeekIn(ChIn, pos) then
  120.     abort("Seek failed");
  121.     fi;
  122. corp;
  123.  
  124. proc unCursor()void:
  125.     byte b;
  126.  
  127.     seek(FilePos);
  128.     read(ChIn; b);
  129.     CRT_Move(CursorLine, CursorColHex);
  130.     write(CRTOut; b : x : -2);
  131.     CRT_Move(CursorLine, CursorColChar);
  132.     ASCIIPut(b);
  133. corp;
  134.  
  135. proc putCursor()void:
  136.     byte b;
  137.  
  138.     seek(FilePos);
  139.     read(ChIn; b);
  140.     CRT_EnterHighLight();
  141.     CRT_Move(CursorLine, CursorColHex);
  142.     write(CRTOut; b : x : -2);
  143.     CRT_Move(CursorLine, CursorColChar);
  144.     ASCIIPut(b);
  145.     CRT_ExitHighLight();
  146. corp;
  147.  
  148. proc displayLine(ulong pos)bool:
  149.     uint c, c1;
  150.     [16] byte buff;
  151.  
  152.     write(CRTOut; pos : x : -POSLEN, ":  ");
  153.     c := 0;
  154.     while c ~= 16 and read(ChIn; buff[c]) do
  155.     write(CRTOut; buff[c] : x : -2, ' ');
  156.     c := c + 1;
  157.     od;
  158.     for c1 from c upto 15 do
  159.     buff[c1] := ' ' - '\e';
  160.     write(CRTOut; "   ");
  161.     od;
  162.     write(CRTOut; " *");
  163.     for c1 from 0 upto 15 do
  164.     ASCIIPut(buff[c1]);
  165.     od;
  166.     write(CRTOut; "*\r\n");
  167.     ioerror(ChIn) = CH_OK
  168. corp;
  169.  
  170. proc displayScreen()void:
  171.     ulong pos;
  172.     uint l;
  173.  
  174.     CRT_Move(0, 0);
  175.     pos := WindowPos;
  176.     l := 0;
  177.     seek(pos);
  178.     while l ~= NLines - 1 and displayLine(pos) do
  179.     l := l + 1;
  180.     pos := pos + 16;
  181.     od;
  182.     l := l + 1;
  183.     while l < NLines - 1 do
  184.     CRT_ClearLine(l);
  185.     l := l + 1;
  186.     od;
  187.     putCursor();
  188. corp;
  189.  
  190. proc scrollUp()void:
  191.     ulong pos;
  192.  
  193.     pos := WindowPos + (NLines - 1) * 16;
  194.     if pos < EndPos then
  195.     CRT_ClearLine(NLines - 1);
  196.     seek(pos);
  197.     pretend(displayLine(pos), void);
  198.     WindowPos := WindowPos + 16;
  199.     if CursorLine = 0 then
  200.         FilePos := FilePos + 16;
  201.         if FilePos > EndPos - 1 then
  202.         CursorColHex := CursorColHex - 3 * (EndPos - 1 - FilePos);
  203.         CursorColChar := CursorColChar - (EndPos - 1 - FilePos);
  204.         FilePos := EndPos - 1;
  205.         fi;
  206.         putCursor();
  207.     else
  208.         CursorLine := CursorLine - 1;
  209.     fi;
  210.     displayStatus();
  211.     else
  212.     endOfFile();
  213.     fi;
  214. corp;
  215.  
  216. proc cursorForward()void:
  217.  
  218.     if FilePos & 0xf = 0xf and CursorLine = NLines - 2 then
  219.     scrollUp();
  220.     fi;
  221.     if FilePos < EndPos - 1 then
  222.     unCursor();
  223.     FilePos := FilePos + 1;
  224.     if FilePos & 0xf = 0 then
  225.         CursorLine := CursorLine + 1;
  226.         CursorColHex := 9;
  227.         CursorColChar := 59;
  228.     else
  229.         CursorColHex := CursorColHex + 3;
  230.         CursorColChar := CursorColChar + 1;
  231.     fi;
  232.     putCursor();
  233.     displayPos();
  234.     else
  235.     endOfFile();
  236.     fi;
  237. corp;
  238.  
  239. proc cursorBackward()void:
  240.  
  241.     if FilePos ~= 0 then
  242.     unCursor();
  243.     FilePos := FilePos - 1;
  244.     if FilePos & 0xf = 0xf then
  245.         CursorColHex := 9 + 30 + 15;
  246.         CursorColChar := 59 + 15;
  247.         if CursorLine = 0 then
  248.         WindowPos := WindowPos - 16;
  249.         CRT_ClearScreen();
  250.         displayScreen();
  251.         displayStatus();
  252.         else
  253.         CursorLine := CursorLine - 1;
  254.         fi;
  255.     else
  256.         CursorColHex := CursorColHex - 3;
  257.         CursorColChar := CursorColChar - 1;
  258.     fi;
  259.     putCursor();
  260.     displayPos();
  261.     else
  262.     startOfFile();
  263.     fi;
  264. corp;
  265.  
  266. proc cursorUp()void:
  267.  
  268.     if FilePos >= 16 then
  269.     unCursor();
  270.     FilePos := FilePos - 16;
  271.     if CursorLine = 0 then
  272.         WindowPos := WindowPos - 16;
  273.         CRT_ClearScreen();
  274.         displayScreen();
  275.         displayStatus();
  276.     else
  277.         CursorLine := CursorLine - 1;
  278.     fi;
  279.     putCursor();
  280.     displayPos();
  281.     else
  282.     startOfFile();
  283.     fi;
  284. corp;
  285.  
  286. proc cursorDown()void:
  287.  
  288.     if CursorLine = NLines - 2 then
  289.     scrollUp();
  290.     fi;
  291.     if FilePos < EndPos - 16 then
  292.     unCursor();
  293.     FilePos := FilePos + 16;
  294.     CursorLine := CursorLine + 1;
  295.     putCursor();
  296.     displayPos();
  297.     else
  298.     endOfFile();
  299.     fi;
  300. corp;
  301.  
  302. proc cursorHome()void:
  303.     bool redraw;
  304.  
  305.     unCursor();
  306.     redraw := WindowPos ~= 0;
  307.     FilePos := 0;
  308.     WindowPos := 0;
  309.     CursorLine := 0;
  310.     CursorColHex := 9;
  311.     CursorColChar := 59;
  312.     if redraw then
  313.     CRT_ClearScreen();
  314.     displayScreen();
  315.     displayStatus();
  316.     putCursor();
  317.     else
  318.     putCursor();
  319.     displayPos();
  320.     fi;
  321. corp;
  322.  
  323. proc pageForward()void:
  324.     ulong pos;
  325.  
  326.     pos := WindowPos + (NLines - 3) * 16;
  327.     if pos < EndPos then
  328.     WindowPos := pos;
  329.     FilePos := FilePos + (NLines - 3) * 16;
  330.     if FilePos >= EndPos then
  331.         FilePos := EndPos - 1;
  332.         CursorLine := (EndPos - WindowPos) / 16 - 1;
  333.         CursorColHex := 9 + FilePos % 16 * 3;
  334.         CursorColChar := 59 + FilePos % 16;
  335.     fi;
  336.     CRT_ClearScreen();
  337.     displayScreen();
  338.     displayStatus();
  339.     else
  340.     endOfFile();
  341.     fi;
  342. corp;
  343.  
  344. proc pageBackward()void:
  345.  
  346.     if WindowPos ~= 0 then
  347.     if WindowPos >= (NLines - 3) * 16 then
  348.         WindowPos := WindowPos - (NLines - 3) * 16;
  349.         FilePos := FilePos - (NLines - 3) * 16;
  350.     else
  351.         FilePos := FilePos - WindowPos;
  352.         WindowPos := 0;
  353.     fi;
  354.     CRT_ClearScreen();
  355.     displayScreen();
  356.     displayStatus();
  357.     else
  358.     startOfFile();
  359.     fi;
  360. corp;
  361.  
  362. proc getHex()byte:
  363.     char ch;
  364.  
  365.     while
  366.     ch := CRT_ReadChar();
  367.     not (ch >= '0' and ch <= '9' or
  368.          ch >= 'a' and ch <= 'f' or
  369.          ch >= 'A' and ch <= 'F' or
  370.          ch = '\r' or ch = '\b')
  371.     do
  372.     od;
  373.     if ch >= 'A' and ch <= 'F' then
  374.     ch - 'A' + 10
  375.     elif ch >= 'a' and ch <= 'f' then
  376.     ch - 'a' + 10
  377.     elif ch = '\r' then
  378.     255
  379.     elif ch = '\b' then
  380.     254
  381.     else
  382.     ch - '0'
  383.     fi
  384. corp;
  385.  
  386. proc gotoDisplay(ulong pos; bool redraw)void:
  387.  
  388.     if not redraw then
  389.     unCursor();
  390.     CursorLine := CursorLine + (pos / 16 - FilePos / 16);
  391.     fi;
  392.     FilePos := pos;
  393.     CursorColHex := (FilePos & 0xf) * 3 + 9;
  394.     CursorColChar := (FilePos & 0xf) + 59;
  395.     if redraw then
  396.     CRT_ClearScreen();
  397.     CursorLine := 0;
  398.     displayScreen();
  399.     displayStatus();
  400.     else
  401.     displayPos();
  402.     fi;
  403.     putCursor();
  404. corp;
  405.  
  406. proc goto()void:
  407.     ulong pos, endPos;
  408.     byte b;
  409.     uint p, q;
  410.     [POSLEN] byte buff;
  411.  
  412.     err("Enter location to go to");
  413.     CRT_Move(NLines - 1, POSCOL);
  414.     write(CRTOut; "      ");
  415.     CRT_Move(NLines - 1, POSCOL);
  416.     p := 0;
  417.     while
  418.     while
  419.         b := getHex();
  420.         b = 0 and p = 0
  421.     do
  422.     od;
  423.     b ~= 255
  424.     do
  425.     if b = 254 then
  426.         if p ~= 0 then
  427.         p := p - 1;
  428.         write(CRTOut; "\b \b");
  429.         fi;
  430.     elif p = POSLEN then
  431.         write(CRTOut; '\(0x07)');
  432.     else
  433.         write(CRTOut; if b < 10 then b + '0' else b - 10 + 'a' fi);
  434.         buff[p] := b;
  435.         p := p + 1;
  436.     fi;
  437.     od;
  438.     if p = 0 then
  439.     clearError();
  440.     err("OK - no goto done");
  441.     displayPos();
  442.     else
  443.     q := POSLEN;
  444.     while p ~= 0 do
  445.         p := p - 1;
  446.         q := q - 1;
  447.         buff[q] := buff[p];
  448.     od;
  449.     while q ~= 0 do
  450.         q := q - 1;
  451.         buff[q] := 0;
  452.     od;
  453.     pos := (make(buff[0], uint) << 20) +
  454.            (make(buff[1], uint) << 16) +
  455.            (make(buff[2], uint) << 12) +
  456.            (make(buff[3], uint) << 8) +
  457.            (make(buff[4], uint) << 4) +
  458.         make(buff[5], uint);
  459.     if pos = FilePos then
  460.         ;
  461.     elif pos < FilePos then
  462.         if pos < WindowPos then
  463.         WindowPos := pos & 0xfffff0;
  464.         gotoDisplay(pos, true);
  465.         else
  466.         gotoDisplay(pos, false);
  467.         fi;
  468.     else
  469.         if pos >= EndPos then
  470.         endOfFile();
  471.         pos := EndPos - 1;
  472.         fi;
  473.         endPos := WindowPos + (NLines - 1) * 16;
  474.         if pos >= endPos then
  475.         WindowPos := pos & 0xfffff0;
  476.         gotoDisplay(pos, true);
  477.         else
  478.         gotoDisplay(pos, false);
  479.         fi;
  480.     fi;
  481.     clearError();
  482.     fi;
  483. corp;
  484.  
  485. proc toDec()void:
  486.     ulong num;
  487.     uint p;
  488.     byte b;
  489.  
  490.     err("Enter hex value to convert");
  491.     CRT_Move(NLines - 1, POSCOL);
  492.     write(CRTOut; "        ");
  493.     CRT_Move(NLines - 1, POSCOL);
  494.     num := 0;
  495.     p := 0;
  496.     while
  497.     while
  498.         b := getHex();
  499.         b = 0 and p = 0
  500.     do
  501.     od;
  502.     b ~= 255
  503.     do
  504.     if b = 254 then
  505.         if p ~= 0 then
  506.         num := num >> 4;
  507.         p := p - 1;
  508.         write(CRTOut; "\b \b");
  509.         fi;
  510.     elif p = 8 then
  511.         write(CRTOut; '\(0x07)');
  512.     else
  513.         write(CRTOut; if b < 10 then b + '0' else b - 10 + 'a' fi);
  514.         num := (num << 4) + b;
  515.         p := p + 1;
  516.     fi;
  517.     od;
  518.     clearError();
  519.     if p ~= 0 then
  520.     err("Decimal value is ");
  521.     CRT_Move(NLines - 1, ERRORCOL + 17);
  522.     CRT_EnterHighLight();
  523.     write(CRTOut; num : u);
  524.     CRT_ExitHighLight();
  525.     fi;
  526.     CRT_Move(NLines - 1, POSCOL + POSLEN);
  527.     for p from POSLEN upto NUMLEN - 1 do
  528.     write(CRTOut; '-');
  529.     od;
  530.     displayPos();
  531. corp;
  532.  
  533. proc toHex()void:
  534.     ulong num;
  535.     uint p;
  536.     char ch;
  537.  
  538.     err("Enter decimal value to convert");
  539.     CRT_Move(NLines - 1, POSCOL);
  540.     write(CRTOut; "           ");
  541.     CRT_Move(NLines - 1, POSCOL);
  542.     num := 0;
  543.     p := 0;
  544.     while
  545.     while
  546.         while
  547.         ch := CRT_ReadChar();
  548.         not (ch >= '0' and ch <= '9' or
  549.              ch = '\r' or ch = '\b')
  550.         do
  551.         od;
  552.         ch = '0' and p = 0
  553.     do
  554.     od;
  555.     ch ~= '\r'
  556.     do
  557.     if ch = '\b' then
  558.         if p ~= 0 then
  559.         num := num / 10;
  560.         p := p - 1;
  561.         write(CRTOut; "\b \b");
  562.         fi;
  563.     elif p = NUMLEN then
  564.         write(CRTOut; '\(0x07)');
  565.     else
  566.         write(CRTOut; ch);
  567.         num := (num * 10) + (ch - '0');
  568.         p := p + 1;
  569.     fi;
  570.     od;
  571.     clearError();
  572.     if p ~= 0 then
  573.     err("Hex value is ");
  574.     CRT_Move(NLines - 1, ERRORCOL + 13);
  575.     CRT_EnterHighLight();
  576.     write(CRTOut; num : x : -8);
  577.     CRT_ExitHighLight();
  578.     fi;
  579.     CRT_Move(NLines - 1, POSCOL + POSLEN);
  580.     for p from POSLEN upto NUMLEN - 1 do
  581.     write(CRTOut; '-');
  582.     od;
  583.     displayPos();
  584. corp;
  585.  
  586. proc helpScreen()void:
  587.  
  588.     CRT_ClearScreen();
  589.     write(CRTOut;
  590.         "\n"
  591.         "\t\tCommands are:\r\n"
  592.         "\n"
  593.         "\tESC - exit\r\n"
  594.         "\tarrow keys - move cursor\r\n"
  595.         "\tshift-left-arrow - move to beginning of file\r\n"
  596.         "\tshift-down-arrow - page forward\r\n"
  597.         "\tshift-up-arrow - page backward\r\n"
  598.         "\tshift-right-arrow - go to specific location\r\n"
  599.         "\tRETURN - scrollUp screen\r\n"
  600.         "\tF1 - convert decimal value to hex\r\n"
  601.         "\tF2 - convert hex value to decimal\r\n"
  602.         "\tF3 - toggle hex/char mode\r\n"
  603.         "\tF10 - redraw screen\r\n"
  604.         "\tothers - replace char when not Read-Only\r\n"
  605.     );
  606.     CRT_Move(16, 10);
  607.     write(CRTOut; "       File size: ", EndPos : u : 8,
  608.           ", hex ", EndPos : x : 6);
  609.     CRT_Move(17, 10);
  610.     write(CRTOut; "Current position: ", FilePos : u : 8,
  611.           ", hex ", FilePos : x : 6);
  612.     CRT_Continue();
  613.     CRT_ClearScreen();
  614.     displayScreen();
  615.     displayStatus();
  616. corp;
  617.  
  618. proc writeByte(byte b)void:
  619.  
  620.     if not SeekOut(ChOut, FilePos) then
  621.     abort("Write seek failed");
  622.     fi;
  623.     write(ChOut; b);
  624.     cursorForward();
  625. corp;
  626.  
  627. proc eatTilde()bool:
  628.  
  629.     if getChar() = '~' then
  630.     true
  631.     else
  632.     err("Invalid; Press HELP for help");
  633.     false
  634.     fi
  635. corp;
  636.  
  637. proc edit()void:
  638.     byte b, b2;
  639.     char cmd;
  640.  
  641.     EndPos := GetInMax(ChIn);
  642.     displayScreen();
  643.     while
  644.     CRT_Move(CursorLine,
  645.          if Binary then CursorColHex else CursorColChar fi);
  646.     cmd := getChar();
  647.     cmd ~= '\(0x1b)'
  648.     do
  649.     if cmd = '\r' then
  650.         scrollUp();
  651.     elif cmd = CSI then
  652.         case getChar()
  653.         incase ' ':
  654.         case getChar()
  655.         incase 'A':
  656.             cursorHome();
  657.         incase '@':
  658.             goto();
  659.         default:
  660.             err("Invalid; Press HELP for help");
  661.         esac;
  662.         incase '?':
  663.         if eatTilde() then
  664.             helpScreen();
  665.         fi;
  666.         incase 'C':
  667.         cursorForward();
  668.         incase 'D':
  669.         cursorBackward();
  670.         incase 'A':
  671.         cursorUp();
  672.         incase 'B':
  673.         cursorDown();
  674.         incase 'S':
  675.         pageForward();
  676.         incase 'T':
  677.         pageBackward();
  678.         incase '9':
  679.         if eatTilde() then
  680.             CRT_Reset();
  681.             CRT_ClearScreen();
  682.             displayScreen();
  683.             displayStatus();
  684.         fi;
  685.         incase '2':
  686.         if eatTilde() then
  687.             CRT_Move(NLines - 1, HEXCOL);
  688.             if Binary then
  689.             Binary := false;
  690.             write(CRTOut; "char");
  691.             else
  692.             Binary := true;
  693.             write(CRTOut; "hex-");
  694.             fi;
  695.         fi;
  696.         incase '1':
  697.         if getChar() = '~' then
  698.             toDec();
  699.         else
  700.             while getChar() ~= '~' do
  701.             od;
  702.             err("Invalid; Press HELP for help");
  703.         fi;
  704.         incase '0':
  705.         if eatTilde() then
  706.             toHex();
  707.         fi;
  708.         default:
  709.         while getChar() ~= '~' do
  710.         od;
  711.         err("Invalid; Press HELP for help");
  712.         esac;
  713.     else
  714.         if cmd >= ' ' and cmd <= '~' then
  715.         if ReadOnly then
  716.             err("Modifications not allowed");
  717.         elif Binary then
  718.             if cmd >= '0' and cmd <= '9' or
  719.                 cmd >= 'a' and cmd <= 'f' or
  720.                 cmd >= 'A' and cmd <= 'F' then
  721.             b :=
  722.                 if cmd >= '0' and cmd <= '9' then
  723.                 cmd - '0'
  724.                 elif cmd >= 'a' and cmd <= 'f' then
  725.                 cmd - 'a' + 10
  726.                 else
  727.                 cmd - 'A' + 10
  728.                 fi;
  729.             CRT_EnterHighLight();
  730.             write(CRTOut;
  731.                   if b >= 10 then b - 10 + 'a' else b + '0' fi);
  732.             CRT_ExitHighLight();
  733.             b2 := getHex();
  734.             if b2 = 255 then
  735.                 writeByte(b);
  736.             elif b2 = 254 then
  737.                 putCursor();
  738.             else
  739.                 writeByte(b << 4 + b2);
  740.             fi;
  741.             else
  742.             err("Bad hexadecimal digit");
  743.             fi;
  744.         else
  745.             write(CRTOut; cmd);
  746.             CRT_Move(CursorLine, CursorColHex);
  747.             write(CRTOut; cmd - '\e' : x : -2);
  748.             writeByte(cmd - '\e');
  749.         fi;
  750.         else
  751.         err("Invalid; Press HELP for help");
  752.         fi;
  753.     fi;
  754.     od;
  755.     if not ReadOnly then
  756.     close(ChOut);
  757.     fi;
  758.     close(ChIn);
  759. corp;
  760.  
  761. proc badUse()void:
  762.  
  763.     writeln("Use is: HEdit [-w] file1 ... fileN");
  764.     exit(1);
  765. corp;
  766.  
  767. proc main()void:
  768.     *char par;
  769.  
  770.     ReadOnly := true;
  771.     Binary := true;
  772.     par := GetPar();
  773.     if par ~= nil and par* = '-' then
  774.     while
  775.         par := par + 1;
  776.         par* ~= '\e'
  777.     do
  778.         case par*
  779.         incase 'w':
  780.         incase 'W':
  781.         ReadOnly := false;
  782.         default:
  783.         badUse();
  784.         esac;
  785.     od;
  786.     par := GetPar();
  787.     fi;
  788.     if par = nil then
  789.     badUse();
  790.     fi;
  791.     CRT_Initialize("HEdit - press HELP for help", 0, 0);
  792.     CRT_AbortDisable();
  793.     NLines := CRT_NLines();
  794.     NCols := CRT_NCols();
  795.     if NCols < 61 then
  796.     writeln("HEdit: less than 61 columns - aborting.");
  797.     CRT_Abort();
  798.     fi;
  799.     open(CRTOut, CRT_PutChar);
  800.     while par ~= nil do
  801.     FilePos := 0;
  802.     WindowPos := 0;
  803.     CursorLine := 0;
  804.     CursorColHex := 9;
  805.     CursorColChar := 59;
  806.     CRT_ClearScreen();
  807.     FileName := par;
  808.     if open(ChIn, Fyle, FileName) then
  809.         displayStatus();
  810.         if not ReadOnly then
  811.         ReOpen(ChIn, ChOut);
  812.         fi;
  813.         if not SeekIn(ChIn, 0) then
  814.         err("Empty file - press a key");
  815.         pretend(getChar(), void);
  816.         else
  817.         edit();
  818.         fi;
  819.     else
  820.         displayStatus();
  821.         err("No such file - press a key");
  822.         pretend(getChar(), void);
  823.     fi;
  824.     par := GetPar();
  825.     od;
  826.     close(CRTOut);
  827.     CRT_Terminate();
  828. corp;
  829.